/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * newProjet.java
 *
 * Created on 3 mai 2011, 21:38:46
 */

package ihm_clarifiee.test;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.swing.JOptionPane;

import com.lavantech.gui.comp.DateTimePicker;

import ihm_clarifiee.application.*;
import ihm_clarifiee.Control.*;
import ihm_clarifiee.Presentation.*;

/**
 *
 * @author Arthur
 */
public class newProjet extends javax.swing.JPanel {

	javax.swing.JFrame container;
    javax.swing.JFrame frameprecedente;
	/** Creates new form newProjet */
    public newProjet() {
        initComponents();
    }
    
    public newProjet(javax.swing.JFrame j, javax.swing.JFrame k){
    	container = j;
    	frameprecedente = k;
    	initComponents();
    	
    	container.setDefaultCloseOperation(container.DISPOSE_ON_CLOSE);
    	frameprecedente.setDefaultCloseOperation(frameprecedente.DISPOSE_ON_CLOSE);
    }
    
    public newProjet(javax.swing.JFrame j){
    	container = j;
    	initComponents();
    }
    
    private void initComponents() {
    	
    	bt_creer = new javax.swing.JButton();
        tf_debut = new DateTimePicker();
    	jScrollPane1 = new javax.swing.JScrollPane();
        ta_descr = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        ta_obj = new javax.swing.JTextArea();
        tf_duree = new javax.swing.JTextField();
        tf_titre = new javax.swing.JTextField();
        lb_titre = new javax.swing.JLabel();
        lb_debut = new javax.swing.JLabel();
        lb_duree = new javax.swing.JLabel();
        lb_descr = new javax.swing.JLabel();
        lb_obj = new javax.swing.JLabel();

        tf_debut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_debutActionPerformed(evt);
            }
        });

        ta_descr.setColumns(20);
        ta_descr.setRows(5);
        jScrollPane1.setViewportView(ta_descr);

        ta_obj.setColumns(20);
        ta_obj.setRows(5);
        jScrollPane2.setViewportView(ta_obj);

        tf_titre.setText("jTextField3");
        tf_titre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_titreActionPerformed(evt);
            }
        });

        lb_titre.setText("Titre:");

        lb_debut.setText("Date de d�but:");

        lb_duree.setText("Dur�e des sprints (jours):");

        lb_descr.setText("Description:");

        lb_obj.setText("Objectifs:");
        
        bt_creer.setText("Creer");
        bt_creer.addActionListener(new java.awt.event.ActionListener(){
        	public void actionPerformed(java.awt.event.ActionEvent evt){
        		bt_creerActionPerformed(evt);
        	}
        });
        
        tf_titre.setText("Titre du projet");
        ta_obj.setText("Objectifs du projet");
        ta_descr.setText("Description du projet");
        tf_duree.setText("1");
        
        
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, true)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(50, 50, 50) //134.134.134
                        .addComponent(lb_titre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_titre, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lb_debut)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_debut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lb_duree)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tf_duree, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(17, 17, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_descr)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(30,30,50) //62.62.120
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_obj)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(21, 30)
                .addComponent(bt_creer,98,98,98))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(14, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tf_titre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lb_titre))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tf_duree, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lb_debut)
                            .addComponent(tf_debut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lb_duree))
                        .addGap(36, 36, 36)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lb_descr)
                            .addComponent(lb_obj))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 153, Short.MAX_VALUE))
                .addGap(23, 23, 23)
                .addComponent(bt_creer,48,48,48))
        );
        
      
              
    }// </editor-fold>

    private void tf_titreActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void tf_debutActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void bt_creerActionPerformed(java.awt.event.ActionEvent evt) {
    	try{
    	String titre = tf_titre.getText(); 
    	String description = ta_descr.getText();
    	String obj = ta_obj.getText();
    	
     	@SuppressWarnings("deprecation")
     	long ldebut = (tf_debut.getDate().getTime() / 86400000);
     	Date debut = new Date(ldebut*86400000 - 7200000);
     	int duree = Integer.valueOf(tf_duree.getText());
    	
    	CUsine us = new CUsine();
    	CProjet cp = new CProjet(us, titre, description, obj, debut, duree);
    	CBacklog cb = new CBacklog(cp);
    	cp.setBacklog(cb);
    	cp.getPresentation().setPBacklog(cb.getPresentation());
    	PProjet pp = cp.getPresentation();
       pp.setVisible(true);
       pp.setSize(950,600);
       if (frameprecedente!=null) {frameprecedente.dispose();}
        if (container != null){container.dispose();}
        System.out.println(debut);
    	}
    	catch(Exception e){
    		e.printStackTrace();
    	}
    }
    
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lb_debut;
    private javax.swing.JLabel lb_descr;
    private javax.swing.JLabel lb_duree;
    private javax.swing.JLabel lb_obj;
    private javax.swing.JLabel lb_titre;
    private javax.swing.JTextArea ta_descr;
    private javax.swing.JTextArea ta_obj;
    private DateTimePicker tf_debut;
    private javax.swing.JTextField tf_duree;
    private javax.swing.JTextField tf_titre;
    private javax.swing.JButton bt_creer;
    // End of variables declaration
}
